package com.ruoyi.web.controller.business;


import com.ruoyi.business.domain.CivilServants;
import com.ruoyi.business.domain.CivilServantsList;
import com.ruoyi.business.domain.vo.ResumeVo;
import com.ruoyi.business.service.CivilServantsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.system.service.impl.SysUserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/civilServants")
@Api(tags = {"机关公务员控制器"})
public class CivilServantsController extends BaseController {

    @Autowired
    CivilServantsService civilServantsService;

    @Autowired
    SysUserServiceImpl sysUserService;

    @GetMapping
    @ApiOperation("查询机关公务员接口")
    public TableDataInfo getList(@ApiParam(value = "用户id") @RequestParam(value = "userId",required = false) Long userId,
                                 @ApiParam(value = "公务员姓名") @RequestParam(value = "name",required = false) String name){
        startPage();
        List<CivilServants> list = civilServantsService.list(userId,name);
        return getDataTable(list);
    }

    @DeleteMapping
    @ApiOperation("单个删除机关公务员接口")
    public AjaxResult delete(@ApiParam(value = "公务员id") Long id) throws Exception {
        civilServantsService.delete(id);
        return success();
    }

    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除机关公务员接口")
    public AjaxResult delete(@ApiParam(value = "公务员id") @PathVariable List<Long> ids) throws Exception {
        for (Long id : ids) {
            civilServantsService.delete(id);
        }
        return success();
    }

    @PostMapping
    @ApiOperation("新增机关公务员接口")
    public AjaxResult add(@RequestBody CivilServants civilServants) throws Exception {
        civilServantsService.add(civilServants);
        return success();
    }


    @PutMapping
    @ApiOperation("修改机关公务员接口")
    public AjaxResult update(@RequestBody CivilServants civilServants) throws Exception {
        civilServantsService.update(civilServants);
        return success();
    }

    @GetMapping("/resume")
    @ApiOperation("机关公务员个人简历接口")
    public AjaxResult resume(@ApiParam(value = "公务员id") Long id) {
        ResumeVo resume = civilServantsService.getResume(id);
        return success(resume);
    }


    @GetMapping("/dept")
    @ApiOperation("查询部门列表信息")
    public AjaxResult deptList() {
        List<SysUser> deptList = sysUserService.getDeptList();
        return success(deptList);
    }
}
